<?php
/**
 * Table Definition for user_group
 */

class Amway_user extends Memcached_DataObject
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'amway_user';                      // table name
    public $id;                              // int(4)  primary_key not_null
    public $user_id;                        // varchar(64)  unique_key
    public $ada;                        // varchar(255)
    public $ada_upline;                        // varchar(255)
    public $ada_rank;                     // varchar(140)
    public $is_active;                        // varchar(255)
    public $created_at;                   // datetime(255)
    public $updated_at;                   // timestamp(255)

    /* Static get */
    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Amway_user',$k,$v); }

    function &pkeyGet($kv)
    {
        return Memcached_DataObject::pkeyGet('Amway_user', $kv);
    }
    /**
     * Check the ada is exist or not
     *
     * @category Amway
     * @package  StatusNet
     * @author   thuclh <thuc.lehuy@gmail.com>
     * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
     * @link     http://status.net/
     */
    function isExist($ada){
        $amway = Amway_user::pkeyGet(array('ada' => $ada));
        return (is_null($amway)) ? false : true;
    }
    // 'update' won't write key columns, so we have to do it ourselves.

    function updateKeys(&$orig) {
        $parts = array();
        foreach (array('user_id', 'ada', 'ada_upline', 'ada_rank', 'is_active', 'created_at', 'updated_at') as $k) {
            if (strcmp($this->$k, $orig->$k) != 0) {
                $parts[] = $k . ' = ' . $this->_quote($this->$k);
            }
        }
        if (count($parts) == 0) {
        // No changes
            return true;
        }
        $toupdate = implode(', ', $parts);

        $table = $this->tableName();
        if(common_config('db','quote_identifiers')) {
            $table = '"' . $table . '"';
        }
        $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
            ' WHERE id = ' . $this->id;
        $orig->decache();
        $result = $this->query($qry);
        if ($result) {
            $this->encache();
        }
        return $result;
    }
}
